package com.shike.core.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {

    /**
     * code说明，前端根据code值，拦截响应，做出相应弹框警告
     *
     * 1 正常
     * 0 失败
     *
     * 401 未登录： 请求需要用户信息接口时，根据token获取不到用户信息
     * 402 身份过期: 请求需要用户信息接口时， token过期
     *
     * 501 请求参数异常: 必填项缺失或不正确
     * ...
     */
    private Integer code;

    private Boolean success;

    private String msg;

    private Object data;


    public static R SUCCESS = new R(1,true,"操作成功",null);

    public static R PASSWORD_ERROR = new R(401,false,"手机号或密码错误！",null);
    public static R USER_DISABLE_ERROR = new R(401,false,"账号已被禁止登录",null);

    public static R NOT_LOGIN_ERROR = new R(401,false,"未登录！",null);
    public static R AUTH_EXP_ERROR = new R(402,false,"身份过期！",null);
    public static R PARAME_ERROR = new R(501,false,"参数异常！",null);


    public static R success(String msg) {
        R r = new R();
        r.setSuccess(true);
        r.setMsg(msg);
        return r;
    }

    public static R successObj(Object data) {
        R r = new R();
        r.setSuccess(true);
        r.setData(data);
        r.setCode(1);
        r.setMsg("操作成功");
        return r;
    }

    public static R error(String msg) {
        R r = new R();
        r.setSuccess(false);
        r.setMsg(msg);
        r.setCode(0);
        return r;
    }

}
